<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /*
            思路：通过bfs获取每一层节点，然后翻转拼接判断是否对称（即回文），注意,需要含有空节点
            
            */
            var isSymmetric = function (root) {
                function levelOrder(root) {
                    if (!root) return true
                    let queue = [root]
                    let res = []
                    while (queue.length) {
                        let len = queue.length
                        res.push([])
                        for (let i = 0; i < len; i++) {
                            let node = queue.shift()
                            if (node) {
                                res[res.length - 1].push(node.val)
                                queue.push(node.left)
                                queue.push(node.right)
                            } else {
                                res[res.length - 1].push(null)
                            }
                        }
                    }
                    return res
                }
                let res = levelOrder(root)
                return res.every((arr) => {
                    return isPali(arr)
                })

                function isPali(arr) {
                    let left = 0
                    let right = arr.length - 1
                    while (left <= right) {
                        if (arr[left] != arr[right]) {
                            return false
                        }
                        left++
                        right--
                    }
                    return true
                }
            }
        </script>
    </body>
</html>
